package com.mdd.front.service.decorate.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mdd.common.entity.decorate.DecoratePage;
import com.mdd.common.mapper.decorate.DecoratePageMapper;
import com.mdd.front.service.decorate.IDecoratePageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.Map;

@Service
public class DecoratePageServiceImpl extends ServiceImpl<DecoratePageMapper, DecoratePage> implements IDecoratePageService {

    @Resource
    DecoratePageMapper decoratePageMapper;

    /**
     * 页面装修详情
     *
     * @param id 主键
     * @return Map<String, Object>
     * @author fzr
     */
    @Override
    public Map<String, Object> detail(Integer id) {
        DecoratePage decoratePage = decoratePageMapper.selectById(id);
        Assert.notNull(decoratePage, "数据不存在!");

        Map<String, Object> map = new LinkedHashMap<>();
        map.put("id", decoratePage.getId());
        map.put("pageType", decoratePage.getPageType());
        map.put("pageData", decoratePage.getPageData());
        return map;
    }

    @Override
    public Map<String, Object> service() {
        LambdaQueryWrapper<DecoratePage> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(DecoratePage::getPageType, 3);
        lambdaQueryWrapper.last("limit 1");
        DecoratePage decoratePage = super.getOne(lambdaQueryWrapper);
        Assert.notNull(decoratePage, "没有设置客服信息");
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("id", decoratePage.getId());
        map.put("pageType", decoratePage.getPageType());
        map.put("pageData", decoratePage.getPageData());
        return map;
    }

}
